home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4STDZE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-22
|
15KB
|
503 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4stdze.cpp
// Title: ZIP+4 Engine
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains code for the class Z4_STANDARDIZE.
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Description: Default constructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M Z4_STANDARDIZE::Z4_STANDARDIZE()
{
Z4_STANDARDIZE::Initialize(CL_INIT_CLASS);
}
//----------------------------------------------------------------------------
// Description: Destructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M Z4_STANDARDIZE::~Z4_STANDARDIZE()
{
Z4_STANDARDIZE::Destroy(FALSE);
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_M Z4_STANDARDIZE::Addr1Display(PSZ psz, RZ4_Z4 rz4)
{
strcpy(psz, rz4.szSecName);
return ;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_M Z4_STANDARDIZE::Addr2Display(PSZ psz, RZ4_Z4 rz4, PCSZ pcszPriNo, PCSZ pcszSecNo, Z4_UNIT unit)
{
CHAR szRange[MAX_RANGE+2];
if (pcszPriNo == NULL)
{
if (strcmp(rz4.szPriLo, rz4.szPriHi) == 0)
pcszPriNo = rz4.szPriLo;
else
pcszPriNo = "";
}
switch (rz4.rectype)
{
case Z4_TYPE_PM:
case Z4_TYPE_GD:
strcpy(psz, rz4.szPriName);
return ;
case Z4_TYPE_POB:
strcpy(psz, rz4.szPriName);
if (pcszPriNo[0])
strcats(psz, RangeDisplay(szRange, pcszPriNo));
return ;
case Z4_TYPE_RR:
strcpy(psz, rz4.szPriName);
if (pcszPriNo[0])
{
strcats(psz, "BOX");
strcats(psz, RangeDisplay(szRange, pcszPriNo));
}
return ;
}
strcpy(psz, RangeDisplay(szRange, pcszPriNo));
strcats(psz, Z4Directional(rz4.predir, Z4_DATA_ABBREV));
strcats(psz, rz4.szPriName);
if (rz4.fOrdinal)
strcat(psz, strord(atol(rz4.szPriName)));
if (rz4.suffix2)
strcats(psz, Z4SuffixFull(rz4.suffix2));
strcats(psz, Z4SuffixAbbrev(rz4.suffix1));
strcats(psz, Z4Directional(rz4.postdir, Z4_DATA_ABBREV));
if (pcszSecNo == NULL)
{
if (strcmp(rz4.szSecLo, rz4.szSecHi) == 0)
pcszSecNo = rz4.szSecLo;
else
pcszSecNo = "";
}
if (pcszSecNo[0])
{
//
// A parsed exceptional unit designator has the exceptional
// designator in both the unit and secondary number field.
// Be careful when peicing it back together.
//
if (strcmp(pcszSecNo, Z4Unit(unit, Z4_DATA_ABBREV)) != 0
|| unit < Z4_UNIT_EXCEPT)
{
if (rz4.unit == Z4_UNIT_BLANK)
{
if (unit != Z4_UNIT_BLANK)
strcats(psz, Z4Unit(unit, Z4_DATA_ABBREV));
else
strcats(psz, "#");
}
else
strcats(psz, Z4Unit(rz4.unit, Z4_DATA_ABBREV));
}
strcats(psz, RangeDisplay(szRange, pcszSecNo));
}
else if (unit != Z4_UNIT_BLANK && unit >= Z4_UNIT_EXCEPT)
strcats(psz, Z4Unit(unit, Z4_DATA_ABBREV));
return ;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns:
//----------------------------------------------------------------------------
VOID FN_M Z4_STANDARDIZE::Clear()
{
szAddress[0] = '\0';
szAddr1[0] = '\0';
szAddr2[0] = '\0';
szLastLine[0] = '\0';
szCity[0] = '\0';
state = Z4_ST_INVALID;
szZip5[0] = '\0';
szAddon[0] = '\0';
szZip4[0] = '\0';
fFacilityOther = FALSE;
fNonDeliverable = FALSE;
return ;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::Complete()
{
szAddress[0] = '\0';
if (szAddr1[0])
strcpy(szAddress, szAddr1);
if (szAddr2[0])
{
if (szAddress[0])
strcat(szAddress, "\r\n");
strcat(szAddress, szAddr2);
}
if (szLastLine[0])
{
if (szAddress[0])
strcat(szAddress, "\r\n");
strcat(szAddress, szLastLine);
}
return TRUE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::CS(RZ4_CX rcx, PCSZ pcszZip5)
{
if (!Z4_INQ::z5_file.Find(Z4_INQ::z5, pcszZip5))
return FALSE;
// Find actual city/state file record!
for (SIZET i = 0; Z4_INQ::z5.cCities; ++i)
{
if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, Z4_INQ::z5.arecid[i]))
return FALSE;
if (Z4_INQ::cs.state == rcx.state
&& strcmp(Z4_INQ::cs.szCity, rcx.szCity) == 0)
break;
}
fFacilityOther = Z4_INQ::cs.facility == Z4_FACILITY_OTHER;
if (!LastLine(Z4_INQ::cs, pcszZip5))
return FALSE;
return Complete();
}
//----------------------------------------------------------------------------
// Description: Destroy object. Free any resources used by object.
// Normally called by destructor.
// Should allow multiple calls from various classes.
// A class should almost always re-init its variables when
// it is destroyed to prevent accidents.
// Parameters: fDestroyAll Destroy parents also?
// Default is TRUE.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::Destroy(BOOL fDestroyAll)
{
Z4_STANDARDIZE::Initialize(CL_INIT_CLASS_VARS);
if (fDestroyAll) // Destroy parent.
Z4_STANDARDIZE_PARENT::Destroy(fDestroyAll);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Initialize object.
// Normally called by constructor.
// Should allow multiple calls from various classes.
// Parameters: sInit Initialization code. May be one of the following:
// CL_INIT_CLASS Reset class variables and
// and dynamic allocations for
// this class only.
// CL_INIT_CLASS_VARS Reset class variables for
// this class only.
// CL_INIT_VARS Reset class variables for
// this class only.
// CL_INIT_ALL Initialize class and all
// parent class, including
// dynamic memory allocation.
// Default is CL_INIT_ALL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::Initialize(SHORT sInit)
{
if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
Z4_STANDARDIZE_PARENT::Initialize(sInit);
return TRUE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::LastLine(RZ4_CS rcs, PCSZ pcszZip5, PCSZ pcszAddon)
{
Assert(pcszZip5);
state = rcs.state;
strcpy(szZip5, pcszZip5);
fFacilityOther = rcs.facility == Z4_FACILITY_OTHER;
strcpy(szCity, (fFacilityOther ? rcs.szLastLineName: rcs.szCity));
if (pcszAddon && pcszAddon[0] != ' ' && pcszAddon[0] != 'N')
{
strcpy(szZip4, pcszZip5);
strcat(szZip4, "-");
strcat(szZip4, pcszAddon);
strcpy(szAddon, pcszAddon);
}
else
szAddon[0] = '\0';
LastLineDisplay(szLastLine, rcs, pcszZip5, pcszAddon);
return TRUE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_M Z4_STANDARDIZE::LastLineDisplay(PSZ psz, RZ4_CS rcs, PCSZ pcszZip5, PCSZ pcszAddon)
{
BOOL fFacilityOther = rcs.facility == Z4_FACILITY_OTHER;
PCSZ pcszCity = (fFacilityOther ? rcs.szLastLineName: rcs.szCity);
sprintf(psz, "%s %s %s", pcszCity, Z4_ST_FILE::Abbreviation(rcs.state), pcszZip5);
if (pcszAddon && pcszAddon[0] != ' ' && pcszAddon[0] != 'N')
{
strcat(psz, "-");
strcat(psz, pcszAddon);
}
return ;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_M Z4_STANDARDIZE::PriRangeDisplay(PSZ psz, RZ4_Z4 rz4)
{
CHAR szRange[MAX_RANGE+2];
if (rz4.szPriLo[0])
{
strcpy(psz, RangeDisplay(szRange, rz4.szPriLo));
if (rz4.szPriHi[0] && strcmp(rz4.szPriLo, rz4.szPriHi) != 0)
{
strcats(psz, "-");
strcats(psz, RangeDisplay(szRange, rz4.szPriHi));
}
}
else
psz[0] = '\0';
return ;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
PSZ FN_M Z4_STANDARDIZE::RangeDisplay(PSZ psz, PCSZ pcszRange)
{
PSZ pszSlash;
strcpy(psz, pcszRange);
if (psz[0] && (pszSlash = strchr(psz + 1, '/')) != NULL)
{
pszSlash--;
pszSlash[0] = ' ';
pszSlash++;
strcpy(pszSlash, strchr(pcszRange + 1, '/') - 1);
}
return psz;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_M Z4_STANDARDIZE::SecRangeDisplay(PSZ psz, RZ4_Z4 rz4)
{
CHAR szRange[MAX_RANGE+2];
if (rz4.szSecLo[0])
{
if (rz4.unit == Z4_UNIT_BLANK)
strcpy(psz, "#");
else
strcpy(psz, Z4Unit(rz4.unit, Z4_DATA_ABBREV));
strcats(psz, RangeDisplay(szRange, rz4.szSecLo));
if (rz4.szSecHi[0] && strcmp(rz4.szSecLo, rz4.szSecHi) != 0)
{
strcats(psz, "-");
strcats(psz, RangeDisplay(szRange, rz4.szSecHi));
}
}
else if (rz4.unit >= Z4_UNIT_EXCEPT)
sprintf(psz, "%s", Z4Unit(rz4.unit, Z4_DATA_ABBREV));
else if (rz4.unit != Z4_UNIT_BLANK)
sprintf(psz, "(%s)", Z4Unit(rz4.unit, Z4_DATA_ABBREV));
else
psz[0] = '\0';
return ;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::Z4(RRECID rrecid, RZ4_PARSE rparse)
{
if (!Z4_INQ::z4_file.Record(Z4_INQ::z4, rrecid))
return FALSE;
if (!Z4_INQ::z5_file.Find(Z4_INQ::z5, Z4_INQ::z4.szZip5))
return FALSE;
if (!Z4_INQ::cs_file.Best(Z4_INQ::cs, Z4_INQ::z5, Z4_INQ::z4.szLastLine))
return FALSE;
//
// This is a problem. I need to specify the correct addon here!!
// POB and FIRM can be ranged??
//
PCSZ pcszAddon = NULL;
if ((Z4_INQ::z4.szPriLo[0] && rparse.szPriNoReformat[0])
|| (!Z4_INQ::z4.szPriLo[0] && !rparse.szPriNoReformat[0]))
{
pcszAddon = Z4_INQ::z4.szAddonLo;
if (Z4_INQ::z4.rectype == Z4_TYPE_POB
&& strcmp(Z4_INQ::z4.szAddonLo, Z4_INQ::z4.szAddonHi) != 0)
{
LONG lAddonHi = atol(Z4_INQ::z4.szAddonHi);
LONG lAddonLo = atol(Z4_INQ::z4.szAddonLo);
LONG lPriLo = atol(Z4_INQ::z4.szPriLo);
LONG lPri = atol(rparse.szPriNoReformat);
LONG lAddon = lAddonLo + (lPri - lPriLo);
if (lAddon >= lAddonLo && lAddon <= lAddonHi)
{
sprintf(szAddon, "%04ld", lAddon);
pcszAddon = szAddon;
}
}
}
if (!LastLine(Z4_INQ::cs, Z4_INQ::z4.szZip5, pcszAddon))
return FALSE;
strcpy(szAddr1, rparse.szSecName);
Addr2Display(szAddr2, Z4_INQ::z4, rparse.szPriNoReformat, rparse.szSecNo, rparse.unit);
fNonDeliverable = (szAddon[0] == 'N' || szAddon[0] == ' ' || !szAddon[0]);
return Complete();
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::Z5(RRECID rrecid, PCSZ pcszZip5)
{
if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, rrecid))
return FALSE;
if (!LastLine(Z4_INQ::cs, pcszZip5))
return FALSE;
return Complete();
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_STANDARDIZE::ZX(RRECID rrecid, PCSZ pcszAddon)
{
if (!Z4_INQ::z4_file.Record(Z4_INQ::z4, rrecid))
return FALSE;
if (!Z4_INQ::z5_file.Find(Z4_INQ::z5, Z4_INQ::z4.szZip5))
return FALSE;
if (!Z4_INQ::cs_file.Best(Z4_INQ::cs, Z4_INQ::z5, Z4_INQ::z4.szLastLine))
return FALSE;
if (!LastLine(Z4_INQ::cs, Z4_INQ::z4.szZip5, pcszAddon))
return FALSE;
Addr1Display(szAddr1, Z4_INQ::z4);
Addr2Display(szAddr2, Z4_INQ::z4);
return Complete();
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------